package com.yisu.auction.api.core.service.impl;

import com.yisu.auction.api.core.mapper.PersonageCollectMapper;
import com.yisu.auction.api.core.service.BaseService;
import com.yisu.auction.api.core.service.IPersonageCollectService;
import com.yisu.auction.api.domain.request.BasePage;
import com.yisu.auction.api.domain.request.prizePackage.CancelMineCollectRequest;
import com.yisu.auction.api.domain.request.prizePackage.PersonageCollectRequest;
import com.yisu.auction.api.domain.vo.indexPackageVos.PrizeListVo;
import com.yisu.auction.ewf.entity.PersonageCollect;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * author: 黄萧林
 * Business Description：个人收藏业务实现
 * createTime：2017/8/17
 */
@Service("IPersonageCollectService")
public class PersonageCollectServiceImpl extends BaseService implements IPersonageCollectService {
    @Resource
    private PersonageCollectMapper personageCollectMapper;


    /**
     * author: 黄萧林
     * Business Description：添加我的收藏
     *
     * @param personageCollectRequest 含prizeId,memberId
     * @return
     */
    @Override
    public boolean addMineCollect(PersonageCollectRequest personageCollectRequest) {
        PersonageCollect insertModel = new PersonageCollect();
        insertModel.setCreateDate(new Date());
        insertModel.setIsValid(true);
        insertModel.setPrizeId(Long.valueOf(personageCollectRequest.getPrizeId()));
        insertModel.setMemberId(Long.valueOf(personageCollectRequest.getMemberId()));
        return personageCollectMapper.insertSelective(insertModel) > 0;
    }

    /**
     * author: 赵杰
     * Business Description：通过prizeId和MemberId，判断是否已收藏
     *
     * @param personageCollectRequest
     * @return
     */
    @Override
    public boolean collectStatus(PersonageCollectRequest personageCollectRequest) {
        return personageCollectMapper.collectStatus(personageCollectRequest)>0;
    }

    /**
     * author:黄萧林
     * Business Description:通过prizeId删除数据
     *
     * @param cancelMineCollectRequest
     * @return
     */
    @Override
    public boolean cancelMineCollect(CancelMineCollectRequest cancelMineCollectRequest) {
        return personageCollectMapper.deleteByPrizeIdAndMemberId(cancelMineCollectRequest) > 0;
    }

    /**
     * author: 赵杰
     * Business Description：获取我的收藏列表
     *
     * @param basePage 含memberId
     * @return
     */
    @Override
    public List<PrizeListVo> getMineCollectList(BasePage basePage) {
        return personageCollectMapper.getMineCollectList(basePage);
    }

}
